<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        class Deque {
            constructor() {
                    this.item = [];
                }
                //前端插入
            addFront(element) {
                    this.item.unshift(element);
                }
                //后端插入
            addBack(element) {
                this.item.push(element);
            }
            removeFront() {
                return this.item.shift();
            }
            removeBack() {
                return this.item.pop();
            }
            toString() {
                return this.item.toString();
            }
            peekBack() {
                if (this.item.length === 0) {
                    return undefined;
                } else {
                    return this.item[this.item.length - 1];
                }
            }
            isEmpty() {
                return this.size() === 0;
            }
            size() {
                return this.item.length;
            }
        }
        // const deque = new Deque();
        // deque.addBack("john");
        // deque.addBack("jack");
        // deque.addFront("camila");
        // console.log("打印所有" + deque.toString());
        // console.log("前一" + deque.addFront());
        // console.log("后一" + deque.addBack());
        // console.log("移除前1" + deque.removeFront());
        // console.log("移除后1" + deque.removeBack());
        // console.log(deque.removeBack());
        // console.log('size' + deque.size());
        function palidromeChecker(aString) {
            //保证有字符串
            if (aString === undefined || aString === null || (aString != null && aString.length == 0)) {
                return false;
            }
            //对字符串做预处理
            const lowerString = aString.toLowerCase().split(" ").join("");
            // return lowerString;
            const deque = new Deque();
            for (let i = 0; i < lowerString.length; i++) {
                deque.addBack(lowerString.charAt(i));
            }
            let isEqual = true;
            let firstCase, lastCase;
            while (deque.size() > 1 && isEqual) {
                firstCase = deque.removeFront();
                lastCase = deque.removeBack();
                if (firstCase !== lastCase) {
                    isEqual = false;
                }
            }
            return isEqual;
        }

        //判断是否为回文
        let string = 'abcba';
        console.log("回文字符", palidromeChecker(string));
    </script>
</body>

</html>